package isssr.bean.boundary;

import isssr.bean.entity.CurrentUser;
import isssr.bean.entity.User;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.primefaces.model.LazyDataModel;

public class SuperTable implements Serializable {

	
	private CurrentUser			current_user;
	private LazySuperDataModel 	dataModel;
	private List<User> 			super_list;
	private ActivityGOBoundary 	main_boundary;
	
	
	public SuperTable()
	{
		this.super_list = new ArrayList<User>();
	}
	
	
	@PostConstruct
	public void init()
	{
		if(this.current_user != null)
		{
			User user 		= this.current_user.getUser();
			this.dataModel 	= new LazySuperDataModel(user);
		}
	}
	
	
	public void setCurrent_user(CurrentUser current_user) {
		this.current_user = current_user;
	}

	public List<User> getSuper_list() {
		return super_list;
	}

	
	public void setSuper_list(List<User> super_list) {
		this.super_list = super_list;
	}


	public LazyDataModel<User> getDataModel() {
		return dataModel;
	}
	
	
	public void setMain_boundary(ActivityGOBoundary main_boundary) {
		this.main_boundary = main_boundary;
	}


	public void insertUser(User to_insert)
	{
		if(to_insert != null)
		{
			if(!this.super_list.contains(to_insert))
				this.super_list.add(to_insert);
		}
	}
	
	
	public void removeUser(User to_remove)
	{
		if(to_remove != null)
			this.super_list.remove(to_remove);
	}
	
	
	public void confirmSelection()
	{
		this.main_boundary.setSuperList(this.super_list);
	}
	
	
	public void cancelSelection()
	{
		this.super_list = this.main_boundary.getSuperList();
	}
	
}
